package com.higgins.server.projectmanagement.datamodel;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.List;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import org.hibernate.annotations.GenericGenerator;
import com.higgins.client.agentapp.datamodel.AgentDTO;
import com.higgins.client.agentapp.datamodel.JobSiteDTO;
import com.higgins.client.dataModel.CoveringLetterDTO;
import com.higgins.client.dataModel.StrategyDTO;
import com.higgins.client.projectmanagement.ProjectItemDTO;
import com.higgins.server.agentapp.datamodel.Agency;

@Entity
@Table(name = "effort")
public class Effort {
    @Id
    @GeneratedValue(generator = "increment")
    @GenericGenerator(name = "increment", strategy = "increment")
	private Long id;
    private Long parentId;
    private Date start;
    private Date stop;
    private Double duration;
	
    
    public Effort() {
        // This is used by JPA
    }
 
	public void setId(Long id)	{
		this.id = id;
	}
	public Long getId()	{
		return id;
	}
	public void setParentId(Long parentId)	{
		this.parentId = parentId;
	}
	public Long getParentId()	{
		return parentId;
	}
	public void setStart(Date start)	{
		this.start = start;
	}
	public Date getStart()	{
		return start;
	}
	public void setStop(Date stop)	{
		setDuration(start, stop);
		this.stop = stop;
	}
	public Date getStop()	{
		return stop;
	}
	public void setDuration(Double duration)	{
		this.duration = duration;
	}
	public Double getDuration()	{
		return duration!=null?duration:0.0;
	}
	public void setDuration(Date start, Date stop)	{
		if (start!=null && stop!=null)	{
			Calendar calStart = Calendar.getInstance();
			Calendar calStop = Calendar.getInstance();
			calStart.setTime(start);
			calStop.setTime(stop);
			double startLong = calStart.getTimeInMillis();
			double stopLong = calStop.getTimeInMillis();
			double difference = stopLong - startLong;
			double seconds = difference/1000;
			double minutes = seconds / 60;
			double hours = minutes / 60;
			duration = hours;
		} else {
			duration = 0.0;
		}
	}
}